//
//  HEApi.m
//  huien
//
//  Created by yiban on 2017/7/5.
//  Copyright © 2017年 lcb. All rights reserved.
//

#import "HEApi.h"

@implementation HEApi

+(void)appHomeWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/app/home"];
    param.requestModel = RequestModel_GET;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSDictionary class]]) {
            object =[LcbJson jsonToObject:baseModel.data withClass:[Home2Model class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)actionWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:[params objectForKey:@"action"]];
    
    NSString *method = [params objectForKey:@"method"];
    if ([method isEqualToString:@"POST"]) {
        param.requestModel = RequestModel_POST;
    }else{
         param.requestModel = RequestModel_GET;
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    SessionModel *sessionModel = [HEShare sessionModel];
    [dict setValue:sessionModel.sessionId forKey:@"sessionId"];
    [dict setValue:[NSString stringWithFormat:@"%ld",sessionModel.session_user.userId] forKey:@"userId"];

    [param addBodys:dict];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
            [YBToast showWithText:msg];
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}

+(void)loginWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileVisitor/login.htm"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSDictionary class]]) {
            object =[LcbJson jsonToObject:baseModel.data withClass:[SessionModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)registerWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileRegistration/registration.htm"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSDictionary class]]) {
            object =[LcbJson jsonToObject:baseModel.data withClass:[SessionModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)smsWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileRegistration/sendSmsPhone"];
    param.requestModel = RequestModel_GET;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
            [YBToast showWithText:msg];
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)smsPwdWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock;
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileUserUpload/sendSMS"];
    param.requestModel = RequestModel_GET;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
            [YBToast showWithText:msg];
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}

+(void)byphoneWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileUserUpload/update/byphone"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}

+(void)resetPWDWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileUserUpload/update_pwd"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {

        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
            [YBToast showWithText:msg];
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)idcardWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileVerification/verification/idcard"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
            [YBToast showWithText:msg];
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)bankListWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/openBankList"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSArray class]]) {
            object =[LcbJson objectArrayToObject:baseModel.data withClass:[ICarModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)moneyListWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/personal_money/my_money"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSDictionary class]]&&[[baseModel.data allKeys] containsObject:@"funds"]) {
            object =[LcbJson objectArrayToObject:baseModel.data[@"funds"] withClass:[FundsModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}


/**
 *消息信息
 */
+(void)systemMessageWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/systemMessage"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data && [baseModel.data isKindOfClass:[NSArray class]]) {
            object =[LcbJson objectArrayToObject:baseModel.data withClass:[SystemMessageModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/**
 *消息删除
 */
+(void)systemMessageDeleteWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/deletes"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/**
 *消息已读
 */
+(void)systemMessageReadWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/reads"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/**
 *邀请好友
 */
+(void)promoteLinksWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMoreIntroduc/get_promote_links"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}


/**
 *认证信息
 */
+(void)basicInformationWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/basic_information"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSArray class]]) {
            object =[LcbJson objectArrayToObject:baseModel.data withClass:[InformationModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);

        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
+(void)homeWithParam:(NSDictionary*)params cache:(BOOL)cache serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileVisitor/appHome"];
    param.requestModel = RequestModel_GET;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSDictionary class]]) {
            object =[LcbJson jsonToObject:baseModel.data withClass:[HomeModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}

+(void)memberCenterWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/member_center"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self cancelRequestWithURL:param.url];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        LcbBaseModel *baseModel = (LcbBaseModel *)response;
        id object = baseModel;
        if (baseModel.code==0 && baseModel.data&& [baseModel.data isKindOfClass:[NSDictionary class]]) {
            object =[LcbJson jsonToObject:baseModel.data withClass:[MemberCenterModel class]];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(object,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/*开启手势密码】数据
 请求路径	/mobileMember/openPatternLock
 请求方式	POST
 Android请求消息体类型	application/json
 IOS请求消息体类型	application/x-www-form-urlencoded
 请求数据
 字段名	类型	是否必填	描述
 sessionId	String	必填	保存用户登录信息的SESSION的ID
 userId	Integer	必填	用户ID。取用户登录或注册成功后，返回的session_user中的userId中的值
 patternLock	String	必填	手势密码值
 修改手势密码】数据 无此参数
 patternStatus	Integer	必填	开启手势密码值为1
 */
+(void)openPatternLockWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/openPatternLock"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/*
 提交【关闭手势密码】数据
 请求：
 请求路径	/mobileMember/closePatternLock
 请求方式	POST
 Android请求消息体类型	application/json
 IOS请求消息体类型	application/x-www-form-urlencoded
 请求数据
 字段名	类型	是否必填	描述
 sessionId	String	必填	保存用户登录信息的SESSION的ID
 userId	Integer	必填	用户ID。取用户登录或注册成功后，返回的session_user中的userId中的值
 patternStatus	Integer	必填	开启手势密码值为0
 【关闭指纹解锁】数据
 fingerPrintStatus	Integer	必填	开启手势密码值为0
 */
+(void)closePatternLockWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/closePatternLock"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/*
 6.	提交【开启指纹解锁】数据
 请求：
 请求路径	/mobileMember/openfingerPrintLock
 请求方式	POST
 Android请求消息体类型	application/json
 IOS请求消息体类型	application/x-www-form-urlencoded
 请求数据
 字段名	类型	是否必填	描述
 sessionId	String	必填	保存用户登录信息的SESSION的ID
 userId	Integer	必填	用户ID。取用户登录或注册成功后，返回的session_user中的userId中的值
 fingerPrintStatus	Integer	必填	开启手势密码值为1
 
 */
+(void)openfingerPrintLockWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/openfingerPrintLock"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
/*开启手势密码】数据
 请求路径	/mobileMember/modifyPatternLock
 请求方式	POST
 Android请求消息体类型	application/json
 IOS请求消息体类型	application/x-www-form-urlencoded
 请求数据
 字段名	类型	是否必填	描述
 sessionId	String	必填	保存用户登录信息的SESSION的ID
 userId	Integer	必填	用户ID。取用户登录或注册成功后，返回的session_user中的userId中的值
 patternLock	String	必填	手势密码值
 */
+(void)modifyPatternLockWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/modifyPatternLock"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}

/*
 提交【关闭指纹解锁】数据
 请求：
 请求路径	/mobileMember/closeFingerPrintLock
 请求方式	POST
 Android请求消息体类型	application/json
 IOS请求消息体类型	application/x-www-form-urlencoded
 请求数据
 字段名	类型	是否必填	描述
 sessionId	String	必填	保存用户登录信息的SESSION的ID
 userId	Integer	必填	用户ID。取用户登录或注册成功后，返回的session_user中的userId中的值
 fingerPrintStatus	Integer	必填	开启手势密码值为0
 */
+(void)closeFingerPrintLockWithParam:(NSDictionary*)params serviceblock:(ApiServiceBlock)serviceblock
{
    LcbRequestParam* param=[[LcbRequestParam alloc]initWithUrl:@"/mobileMember/closeFingerPrintLock"];
    param.requestModel = RequestModel_POST;
    [param addBodys:params];
    [self requestWithParam:param  progressBlock:nil success:^(id response,NSString* msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(response,msg);
        });
    } failure:^(NSString *errorMsg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            !serviceblock?:serviceblock(nil,errorMsg);
            [YBToast showWithText:errorMsg];
        });
    }];
}
@end
